package com.yang.controller;

import com.yang.service.FileService;
import com.yang.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 不是菜鸡爱编程
 * @Date: 2024/02/24/19:32
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("file")
public class FileController {

    @Autowired
    private FileService fileService;
    @PostMapping("/upload")
    public R upload(MultipartFile file){
        return R.ok().setData(fileService.upload(file));
    }

    /**
     * 文件下载
     * @param fileFullName
     * @param response
     * @throws IOException
     */
    @GetMapping("/download/{fileFullName}")
    public void downloadFile(@PathVariable String fileFullName, @RequestParam(required = false) String loginId,
                             @RequestParam(required = false) String token,
                             HttpServletResponse response) throws IOException {
        fileService.downloadFile(fileFullName, loginId, token, response);
    }

}
